/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//package MuleGame;
package MuleBackend;

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

/**
 * 
* This class contains methods and variables necessary for initializing
* and instantiating a graphical user interface that is displayed whenever
* a round is complete. It displays a summary GUI that is displayed at the end
* of each round. It will also hold information pertinent to player-interactive 
* features associated with land and good auction, such as action listeners and 
* parameters involved in system.in input. 
* 
*/
public class StatusPanel extends JPanel{
	
	private JLabel[] player1Label;
	private JLabel[] player2Label;
	private JLabel[] player3Label;
	private JLabel[] player4Label;
	private JLabel[] totalLabel;
	private JLabel titleLabel;
	private JLabel[] displayLabel;
	
	private int[] playerLocX, playerLocY;
	
	ArrayList<ImageIcon> playerImage;
	ArrayList<Integer> x,y;
	
	/**
	 * this is the constructor for StatusGUI class
	 */
	public StatusPanel(){
		setLayout(null);
		player1Label = new JLabel[5];
		player2Label = new JLabel[5];
		player3Label = new JLabel[5];
		player4Label = new JLabel[5];
		displayLabel = new JLabel[4];
		totalLabel = new JLabel[2];
		playerImage = new ArrayList<ImageIcon>();
		x = new ArrayList<Integer>();
		y = new ArrayList<Integer>();
		playerLocX = new int[4];
		playerLocY = new int[4];
		buildGUI();
	}
	
	public void buildGUI(){
		
		titleLabel = new JLabel("Summary");
		titleLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
		titleLabel.setBounds(400,0,100,30);
		
		displayLabel[0] = new JLabel("Money");
		displayLabel[0].setFont(new java.awt.Font("Tahoma", 0, 18));
		displayLabel[0].setBounds(200,50,100,20);
		displayLabel[1] = new JLabel("Plot");
		displayLabel[1].setFont(new java.awt.Font("Tahoma", 0, 18));
		displayLabel[1].setBounds(350,50,100,20);
		displayLabel[2] = new JLabel("Assets");
		displayLabel[2].setFont(new java.awt.Font("Tahoma", 0, 18));
		displayLabel[2].setBounds(500,50,100,20);
		displayLabel[3] = new JLabel("Total");
		displayLabel[3].setFont(new java.awt.Font("Tahoma", 0, 18));
		displayLabel[3].setBounds(650,50,100,20);
		
		player1Label[0] = new JLabel("Player1");
		player1Label[0].setBounds(5,120,150,20);
		player1Label[1] = new JLabel("...");
		player1Label[1].setBounds(200,120,40,20);
		player1Label[2] = new JLabel("...");
		player1Label[2].setBounds(350,120,40,20);
		player1Label[3] = new JLabel("...");
		player1Label[3].setBounds(500,120,40,20);
		player1Label[4] = new JLabel("...");
		player1Label[4].setBounds(650,120,40,20);
		
		player2Label[0] = new JLabel("Player2");
		player2Label[0].setBounds(5,190,150,20);
		player2Label[1] = new JLabel("...");
		player2Label[1].setBounds(200,190,40,20);
		player2Label[2] = new JLabel("...");
		player2Label[2].setBounds(350,190,40,20);
		player2Label[3] = new JLabel("...");
		player2Label[3].setBounds(500,190,40,20);
		player2Label[4] = new JLabel("...");
		player2Label[4].setBounds(650,190,40,20);
		
		player3Label[0] = new JLabel("Player3");
		player3Label[0].setBounds(5,260,150,20);
		player3Label[1] = new JLabel("...");
		player3Label[1].setBounds(200,260,40,20);
		player3Label[2] = new JLabel("...");
		player3Label[2].setBounds(350,260,40,20);
		player3Label[3] = new JLabel("...");
		player3Label[3].setBounds(500,260,40,20);
		player3Label[4] = new JLabel("...");
		player3Label[4].setBounds(650,260,40,20);
		
		player4Label[0] = new JLabel("Player4");
		player4Label[0].setBounds(5,330,150,20);
		player4Label[1] = new JLabel("...");
		player4Label[1].setBounds(200,330,40,20);
		player4Label[2] = new JLabel("...");
		player4Label[2].setBounds(350,330,40,20);
		player4Label[3] = new JLabel("...");
		player4Label[3].setBounds(500,330,40,20);
		player4Label[4] = new JLabel("...");
		player4Label[4].setBounds(650,330,40,20);
		
		totalLabel[0] = new JLabel("Colony Total");
		totalLabel[0].setFont(new java.awt.Font("Tahoma", 0, 18));
		totalLabel[0].setBounds(480,390,100,20);
		totalLabel[1] = new JLabel("");
		totalLabel[1].setBounds(650,390,40,20);
		
		add(titleLabel);
		add(displayLabel[0]);
		add(displayLabel[1]);
		add(displayLabel[2]);
		add(displayLabel[3]);
		add(player1Label[0]);
		add(player1Label[1]);
		add(player1Label[2]);
		add(player1Label[3]);
		add(player1Label[4]);
		add(player2Label[0]);
		add(player2Label[1]);
		add(player2Label[2]);
		add(player2Label[3]);
		add(player2Label[4]);
		add(player3Label[0]);
		add(player3Label[1]);
		add(player3Label[2]);
		add(player3Label[3]);
		add(player3Label[4]);
		add(player4Label[0]);
		add(player4Label[1]);
		add(player4Label[2]);
		add(player4Label[3]);
		add(player4Label[4]);
		add(totalLabel[0]);
		add(totalLabel[1]);
	}
	
	public void remove(){
		player1Label[0].setText("");
		player1Label[1].setText("");
		player1Label[2].setText("");
		player1Label[3].setText("");
		player1Label[4].setText("");
		player2Label[0].setText("");
		player2Label[1].setText("");
		player2Label[2].setText("");
		player2Label[3].setText("");
		player2Label[4].setText("");
		player3Label[0].setText("");
		player3Label[1].setText("");
		player3Label[2].setText("");
		player3Label[3].setText("");
		player3Label[4].setText("");
		player4Label[0].setText("");
		player4Label[1].setText("");
		player4Label[2].setText("");
		player4Label[3].setText("");
		player4Label[4].setText("");
	}
	
	public void paint(Graphics g){
		super.paint(g);
		
		g.setColor(Color.BLACK);
		g.drawRect(150,40,600,340);
		g.drawLine(5, 100, 750, 100);
		g.drawLine(150, 170, 750, 170);
		g.drawLine(150, 240, 750, 240);
		g.drawLine(150, 310, 750, 310);
		g.drawLine(300, 40, 300, 380);
		g.drawLine(450, 40, 450, 380);
		g.drawLine(600, 40, 600, 380);
		g.drawRect(600, 380, 150, 50);
		
		ArrayList<Player> players = GameDriver.game.getPlayerList();
		
		for (int i=0; i<players.size();i++){
			g.drawImage(players.get(i).getRace().getImage(),playerLocX[i],playerLocY[i],75,75,null);
		}
		
	}
	
	public void drawPlayer(){
		playerLocX[0] = 900; playerLocY[0] = 400;
		playerLocX[1] = 970; playerLocY[1] = 400;
		playerLocX[2] = 1040; playerLocY[2] = 400;
		playerLocX[3] = 1110; playerLocY[3] = 400;
		
		while(playerLocY[0]>=110){
			for (int i=0; i<playerLocX.length;i++){
				if (playerLocX[i]>=90){
					playerLocX[i] = playerLocX[i]-10;
				}else{
					playerLocY[i] = playerLocY[i]-10;
				}
			}
			update(getGraphics());
			sleepThread();
		}
		update();
	}
	
	private void sleepThread(){
		try {
			Thread.sleep(50);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	public void update(){
		   ArrayList<Player> players = GameDriver.game.getPlayerList();
		   if (players.size()>=1){
			   player1Label[0].setText(players.get(0).getName());
			   player1Label[1].setText(players.get(0).getMoney()+"");
			   player1Label[2].setText(players.get(0).ownedLand()+"");
			   player1Label[3].setText("");
			   player1Label[4].setText("");
		   }else{
			   player1Label[0].setVisible(false);
			   player1Label[1].setVisible(false);
			   player1Label[2].setVisible(false);
			   player1Label[3].setVisible(false);
			   player1Label[4].setVisible(false);
		   }
		   if (players.size()>=2){
			   player2Label[0].setText(players.get(1).getName());
			   player2Label[1].setText(players.get(1).getMoney()+"");
			   player2Label[2].setText(players.get(1).ownedLand()+"");
			   player2Label[3].setText("");
			   player2Label[4].setText("");
		   }else{
			   player2Label[0].setVisible(false);
			   player2Label[1].setVisible(false);
			   player2Label[2].setVisible(false);
			   player2Label[3].setVisible(false);
			   player2Label[4].setVisible(false);
		   }
		   if (players.size()>=3){
			   player3Label[0].setText(players.get(2).getName());
			   player3Label[1].setText(players.get(2).getMoney()+"");
			   player3Label[2].setText(players.get(2).ownedLand()+"");
			   player3Label[3].setText("");
			   player3Label[4].setText("");
		   }else{
			   player3Label[0].setVisible(false);
			   player3Label[1].setVisible(false);
			   player3Label[2].setVisible(false);
			   player3Label[3].setVisible(false);
			   player3Label[4].setVisible(false);
		   }
		   if (players.size()>=4){
			   player4Label[0].setText(players.get(3).getName());
			   player4Label[1].setText(players.get(3).getMoney()+"");
			   player4Label[2].setText(players.get(3).ownedLand()+"");
			   player4Label[3].setText("");
			   player4Label[4].setText("");
		   }else{
			   player4Label[0].setVisible(false);
			   player4Label[1].setVisible(false);
			   player4Label[2].setVisible(false);
			   player4Label[3].setVisible(false);
			   player4Label[4].setVisible(false);
		   }
		   totalLabel[1].setText("");
	   }
}
